/*
 ============================================================================
 Name		: BackgroundMonitor.h
 Author	  : Lenka Litvova
 Version	 : 1.0
 Copyright   : Copyright belongs to Lenka Litvova
 Description : CBackgroundMonitor declaration
 ============================================================================
 */

#ifndef BACKGROUNDMONITOR_H
#define BACKGROUNDMONITOR_H

#include <e32base.h>	// For CActive, link against: euser.lib
#include <e32std.h>		// For RTimer, link against: euser.lib

#include "EventObserver.h"
#include <APGTASK.H>
#include <coemain.h>
#include "APGCLI.H"

class CBackgroundMonitorAppUi;

class CBackgroundMonitor : public CActive
	{
public:
	// Cancel and destroy
	~CBackgroundMonitor();

	// Two-phased constructor.
	static CBackgroundMonitor* NewL(MEventObserver *aObserver);

	// Two-phased constructor.
	static CBackgroundMonitor* NewLC(MEventObserver *aObserver);

public:
	// New functions
	// Function for making the initial request
	void StartL(CArrayFixFlat<TUid> *aMonitored);
	
	void StartL();
	void Continue();
	
	// How to cancel me
	void DoCancel();

private:
	// C++ constructor
	CBackgroundMonitor(MEventObserver *aObserver);

	// Second-phase constructor
	void ConstructL();

private:
	// From CActive
	// Handle completion
	void RunL();

	// Override to handle leaves from RunL(). Default implementation causes
	// the active scheduler to panic.
	TInt RunError(TInt aError);

private:
	RTimer iTimer; // Provides async timing service
	MEventObserver *iObserver;
	//CBackgroundMonitorAppUi *iAppUi;
	TApaTaskList iTaskList;
	CArrayFixFlat<TUid> *iMonitored;
	CArrayFixFlat<TUid> *iChecked;
	TInt iLastCount;
	TBool iAll;
	TBool iCancel;
	RApaLsSession iLs;
	};

#endif // BACKGROUNDMONITOR_H
